package lzm.dao;

import lzm.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface StudentRepository extends JpaRepository<Student,Long> {

    /**
     * 通过Id查询对象
     * @param id
     * @return
     */
    @Query("from Student t where t.id = ?1")
    public Student findById(Long id);

    /**
     * 查询所有对象，返回集合
     * @return
     */
    @Query("from Student t")
    public List<Student> findAll();

    /**
     * 通过id更新对象
     * @param name
     * @param id
     * @return
     */
    @Modifying
    @Query("update Student t set t.name = ?1 where t.id = ?2")
    void updateName(String name, Long id);

    /**
     * 通过名称查找对象
     * @return
     */
    @Query("from Student t where t.name = ?1 ")
    public List<Student> findByName(String name);


}
